<%--
  Created by IntelliJ IDEA.
  User: yangtao
  Date: 2021-12-07
  Time: 14:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/main.css">
<style>
    label.xrequired:before {
        content: '* ';
        color: red;
        font-size: large;
    }

    .tab-content > .active {
        display: block;
    }

    .form_select2 {
        margin-bottom: 8px !important;
    }

    .select2_main {

    }

    .select2_other {

    }

    /*同时拥有这个中class*/
    .select2.select2-container.select2-container--default {
        width: 100% !important;
    }
</style>
<div class="app-title">
    <div>
        <h1><i class="fa fa-pie-chart"></i> 更新项目</h1>
    </div>
    <ul class="app-breadcrumb breadcrumb">
        <li class="breadcrumb-item"><i class="fa fa-home fa-lg"></i></li>
        <li class="breadcrumb-item"><a href="#">技术创新</a></li>
        <li class="breadcrumb-item"><a href="#">更新项目</a></li>
    </ul>
</div>

<div class="tile mb-4">
    <div class="row" style="margin-bottom: 2rem;">
        <div class="col-lg-12">
            <div class="bs-component">
                <%--<ul class="nav nav-tabs">
                    <li class="nav-item"><a class="nav-link active" data-toggle="tab" href="#suggest">合理化建议</a></li>
                    <li class="nav-item"><a class="nav-link hover" data-toggle="tab" href="#ppt">PPT课件</a></li>
                    <li class="nav-item"><a class="nav-link" data-toggle="tab" href="#paper">技术论文</a></li>
                    <li class="nav-item"><a class="nav-link" data-toggle="tab" href="#QC">QC活动</a></li>
                    <li class="nav-item"><a class="nav-link" data-toggle="tab" href="#research">科研项目</a></li>
                    <li class="nav-item"><a class="nav-link" data-toggle="tab" href="#patent">专利</a></li>
                </ul>--%>
                <div class="tab-content" id="myTabContent">
                    <input id="pkId" value="${project.pkId}" type="hidden">
                    <div class="tab-pane fade" id="suggest">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="tile">
                                    <div class="row" style="justify-content: center;">
                                        <div class="col-lg-6">
                                            <form>
                                                <div class="form-group">
                                                    <label class="xrequired">建议名称：</label>
                                                    <input class="form-control" id="suggestItemName" type="text"
                                                           onblur="checkValue(this)"
                                                           placeholder="请输入建议名称">
                                                </div>

                                                <div class="form-group">
                                                    <label class="">提出时间：</label>
                                                    <input class="form-control form_datetime" id="suggestItemStartDate"
                                                           type="text"
                                                           placeholder="请选择提出时间" autocomplete="off">
                                                </div>
                                                <div class="form-group">
                                                    <label class="xrequired">奖励等级：</label>
                                                    <select class="form-control" onchange="selValue(this)">
                                                        <option value="">请选择</option>
                                                        <option value="c1">川庆公司一等奖</option>
                                                        <option value="c2">川庆公司二等奖</option>
                                                        <option value="c3">川庆公司三等奖</option>
                                                        <option value="g1">公司一等奖</option>
                                                        <option value="g2">公司二等奖</option>
                                                        <option value="g3">公司三等奖</option>
                                                        <option value="g4">公司四等奖</option>
                                                        <option value="g5">公司五等奖</option>
                                                    </select>
                                                    <input type="hidden" id="suggestItemRewardClass" value=""/>
                                                </div>
                                                <div class="form-group">
                                                    <label>奖励时间：</label>
                                                    <input class="form-control form_datetime" id="suggestItemRewardDate"
                                                           type="text"
                                                           placeholder="请输入奖励时间" autocomplete="off">
                                                </div>
                                                <div class="form-group">
                                                    <label class="xrequired">主要参与人员：</label>
                                                    <select class="form-control select2_main" id="suggestMainStaff"
                                                            data-placeholder="--请选择--">
                                                        <optgroup label="员工">
                                                            <option></option>
                                                            <c:forEach items="${staffList}" var="staff">
                                                                <option value="${staff.pkId}">${staff.staffName}</option>
                                                            </c:forEach>
                                                        </optgroup>
                                                    </select>
                                                </div>
                                                <div class="form-group">
                                                    <label class="">其他参与人员：</label>
                                                    <select class="form-control select2_other"
                                                            id="suggestOtherStaff" data-placeholder="--请选择--"
                                                            multiple="">
                                                        <optgroup label="员工">
                                                            <c:forEach items="${staffList}" var="staff">
                                                                <option value="${staff.pkId}">${staff.staffName}</option>
                                                            </c:forEach>
                                                        </optgroup>
                                                    </select>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                    <div class="tile-footer">
                                        <button class="btn btn-primary" type="button" onclick="save('suggest')">提交
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="tab-pane fade" id="ppt">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="tile">
                                    <div class="row" style="justify-content: center;">
                                        <div class="col-lg-6">
                                            <form>
                                                <div class="form-group">
                                                    <label class="xrequired">PPT名称：</label>
                                                    <input class="form-control" id="pptItemName" type="text"
                                                           onblur="checkValue(this)"
                                                           placeholder="请输入PPT名称">
                                                </div>
                                                <div class="form-group">
                                                    <label class="">制作时间：</label>
                                                    <input class="form-control form_datetime" id="pptItemStartDate"
                                                           type="text"
                                                           placeholder="请选择提出时间" autocomplete="off">
                                                </div>
                                                <div class="form-group">
                                                    <label class="xrequired">发布等级：</label>
                                                    <%--公司发布、中心发布--%>
                                                    <select class="form-control" onchange="selValue(this)">
                                                        <option value="">请选择</option>
                                                        <option value="p1">中心发布</option>
                                                        <option value="p2">公司发布</option>
                                                    </select>
                                                    <input type="hidden" id="pptItemPublishClass">
                                                </div>
                                                <div class="form-group">
                                                    <label class="xrequired">奖励等级：</label>
                                                    <select class="form-control" onchange="selValue(this)">
                                                        <option value="">请选择</option>
                                                        <option value="c1">川庆公司一等奖</option>
                                                        <option value="c2">川庆公司二等奖</option>
                                                        <option value="c3">川庆公司三等奖</option>
                                                        <option value="g1">公司一等奖</option>
                                                        <option value="g2">公司二等奖</option>
                                                        <option value="g3">公司三等奖</option>
                                                    </select>
                                                    <input type="hidden" id="pptItemRewardClass" value=""/>
                                                </div>
                                                <div class="form-group">
                                                    <label>奖励时间：</label>
                                                    <input class="form-control form_datetime" id="pptItemRewardDate"
                                                           type="text"
                                                           placeholder="请输入奖励时间" autocomplete="off">
                                                </div>
                                                <div class="form-group">
                                                    <label class="xrequired">主要制作人员：</label>
                                                    <select class="form-control select2_main" id="pptMainStaff"
                                                            data-placeholder="--请选择--">
                                                        <optgroup label="员工">
                                                            <option></option>
                                                            <c:forEach items="${staffList}" var="staff">
                                                                <option value="${staff.pkId}">${staff.staffName}</option>
                                                            </c:forEach>
                                                        </optgroup>
                                                    </select>
                                                </div>
                                                <div class="form-group">
                                                    <label class="">其他制作人员：</label>
                                                    <select class="form-control select2_other" id="pptOtherStaff"
                                                            data-placeholder="--请选择--">
                                                        <optgroup label="员工">
                                                            <option></option>
                                                            <c:forEach items="${staffList}" var="staff">
                                                                <option value="${staff.pkId}">${staff.staffName}</option>
                                                            </c:forEach>
                                                        </optgroup>
                                                    </select>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                    <div class="tile-footer">
                                        <button class="btn btn-primary" type="button" onclick="save('ppt')">提交</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="tab-pane fade" id="paper">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="tile">
                                    <div class="row" style="justify-content: center;">
                                        <div class="col-lg-6">
                                            <form>
                                                <div class="form-group">
                                                    <label class="xrequired">论文名称：</label>
                                                    <input class="form-control" id="paperItemName" type="text"
                                                           onblur="checkValue(this)"
                                                           placeholder="请输入论文名称">
                                                </div>
                                                <div class="form-group">
                                                    <label class="">论文摘要：</label>
                                                    <input class="form-control" id="paperItemContent" type="text"
                                                           onblur="checkValue(this)"
                                                           placeholder="请输入论文摘要">
                                                </div>
                                                <div class="form-group">
                                                    <label class="">完成时间：</label>
                                                    <input class="form-control form_datetime" id="paperItemStartDate"
                                                           type="text"
                                                           placeholder="请选择完成时间" autocomplete="off">
                                                </div>
                                                <div class="form-group">
                                                    <label class="xrequired">发表等级：</label>
                                                    <select class="form-control" onchange="selValue(this)">
                                                        <option value="">请选择</option>
                                                        <option value="p3">集团公司期刊</option>
                                                        <option value="p4">公司期刊</option>
                                                        <option value="p4">核心期刊</option>

                                                    </select>
                                                    <input type="hidden" id="paperItemPublishClass" value=""/>

                                                </div>
                                                <div class="form-group">
                                                    <label>发表时间：</label>
                                                    <input class="form-control form_datetime" id="paperItemPublishDate"
                                                           type="text"
                                                           placeholder="请输入发表时间" autocomplete="off">
                                                </div>
                                                <div class="form-group">
                                                    <label class="xrequired">第一作者：</label>
                                                    <select class="form-control select2_main" id="paperMainStaff"
                                                            data-placeholder="--请选择--">
                                                        <optgroup label="员工">
                                                            <option></option>
                                                            <c:forEach items="${staffList}" var="staff">
                                                                <option value="${staff.pkId}">${staff.staffName}</option>
                                                            </c:forEach>
                                                        </optgroup>
                                                    </select>
                                                </div>
                                                <div class="form-group">
                                                    <label class="">其他作者：</label>
                                                    <select class="form-control select2_other" id="paperOtherStaff"
                                                            data-placeholder="--请选择--"
                                                            multiple="">
                                                        <optgroup label="员工">
                                                            <c:forEach items="${staffList}" var="staff">
                                                                <option value="${staff.pkId}">${staff.staffName}</option>
                                                            </c:forEach>
                                                        </optgroup>
                                                    </select>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                    <div class="tile-footer">
                                        <button class="btn btn-primary" type="button" onclick="save('paper')">提交
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="tab-pane fade" id="QC">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="tile">
                                    <div class="row" style="justify-content: center;">
                                        <div class="col-lg-6">
                                            <form>
                                                <div class="form-group">
                                                    <label class="xrequired">活动名称：</label>
                                                    <input class="form-control" id="QCItemName" type="text"
                                                           onblur="checkValue(this)"
                                                           placeholder="请输入活动名称">
                                                </div>
                                                <div class="form-group">
                                                    <label class="">完成时间：</label>
                                                    <input class="form-control form_datetime" id="QCItemStartDate"
                                                           type="text"
                                                           placeholder="请选择完成时间" autocomplete="off">
                                                </div>
                                                <div class="form-group">
                                                    <label class="xrequired">是否完成活动报告：</label>
                                                    <select class="form-control" onchange="selValue(this)">
                                                        <option value="">请选择</option>
                                                        <option value="0">未完成</option>
                                                        <option value="1">完成</option>
                                                    </select>
                                                    <input type="hidden" id="QCItemReport" value=""/>
                                                </div>
                                                <div class="form-group">
                                                    <label class="xrequired">奖励等级：</label>
                                                    <select class="form-control" onchange="selValue(this)">
                                                        <option value="">请选择</option>
                                                        <option value="c1">川庆公司一等奖</option>
                                                        <option value="c2">川庆公司二等奖</option>
                                                        <option value="c3">川庆公司三等奖</option>
                                                        <option value="g1">公司一等奖</option>
                                                        <option value="g2">公司二等奖</option>
                                                        <option value="g3">公司三等奖</option>
                                                    </select>
                                                    <input type="hidden" id="QCItemRewardClass" value=""/>
                                                </div>
                                                <div class="form-group">
                                                    <label>奖励时间：</label>
                                                    <input class="form-control form_datetime" id="QCItemRewardDate"
                                                           type="text"
                                                           placeholder="请输入奖励时间" autocomplete="off">
                                                </div>
                                                <div class="form-group">
                                                    <label class="xrequired">报告编写人：</label>
                                                    <select class="form-control select2_main" id="QCMainStaff"
                                                            data-placeholder="--请选择--">
                                                        <optgroup label="员工">
                                                            <option value="" selected="">--请选择--</option>
                                                            <c:forEach items="${staffList}" var="staff">
                                                                <option value="${staff.pkId}">${staff.staffName}</option>
                                                            </c:forEach>
                                                        </optgroup>
                                                    </select>
                                                </div>
                                                <div class="form-group">
                                                    <label class="">其他主要人员：</label>
                                                    <select class="form-control select2_other" id="QCOtherStaff"
                                                            data-placeholder="--请选择--"
                                                            multiple="">
                                                        <optgroup label="员工">
                                                            <c:forEach items="${staffList}" var="staff">
                                                                <option value="${staff.pkId}">${staff.staffName}</option>
                                                            </c:forEach>
                                                        </optgroup>
                                                    </select>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                    <div class="tile-footer">
                                        <button class="btn btn-primary" type="button" onclick="save('QC')">提交</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="tab-pane fade" id="research">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="tile">
                                    <div class="row" style="justify-content: center;">
                                        <div class="col-lg-6">
                                            <form>
                                                <div class="form-group">
                                                    <label class="xrequired">项目名称：</label>
                                                    <input class="form-control" id="researchItemName" type="text"
                                                           onblur="checkValue(this)"
                                                           placeholder="请输入项目名称">
                                                </div>
                                                <div class="form-group">
                                                    <label class="">研究时间：</label>
                                                    <input class="form-control form_datetime" id="researchItemStartDate"
                                                           type="text"
                                                           placeholder="请选择研究时间" autocomplete="off">
                                                </div>
                                                <div class="form-group">
                                                    <label class="xrequired">奖励等级：</label>
                                                    <select class="form-control" onchange="selValue(this)">
                                                        <option value="">请选择</option>
                                                        <option value="c1">川庆公司一等奖</option>
                                                        <option value="c2">川庆公司二等奖</option>
                                                        <option value="c3">川庆公司三等奖</option>
                                                        <option value="g1">公司一等奖</option>
                                                        <option value="g2">公司二等奖</option>
                                                        <option value="g3">公司三等奖</option>
                                                    </select>
                                                    <input type="hidden" id="researchItemRewardClass" value=""/>
                                                </div>
                                                <div class="form-group">
                                                    <label>奖励时间：</label>
                                                    <input class="form-control form_datetime"
                                                           id="researchItemRewardDate"
                                                           type="text"
                                                           placeholder="请输入奖励时间" autocomplete="off">
                                                </div>
                                                <div class="form-group">
                                                    <label class="xrequired">项目长：</label>
                                                    <select class="form-control select2_main" id="researchMainStaff"
                                                            data-placeholder="--请选择--">
                                                        <optgroup label="员工">
                                                            <option></option>
                                                            <c:forEach items="${staffList}" var="staff">
                                                                <option value="${staff.pkId}">${staff.staffName}</option>
                                                            </c:forEach>
                                                        </optgroup>
                                                    </select>
                                                </div>
                                                <div class="form-group">
                                                    <label class="">主要研究人员：</label>
                                                    <select class="form-control select2_other" id="researchOtherStaff"
                                                            data-placeholder="--请选择--"
                                                            multiple="">
                                                        <optgroup label="员工">
                                                            <c:forEach items="${staffList}" var="staff">
                                                                <option value="${staff.pkId}">${staff.staffName}</option>
                                                            </c:forEach>
                                                        </optgroup>
                                                    </select>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                    <div class="tile-footer">
                                        <button class="btn btn-primary" type="button" onclick="save('research')">提交
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="tab-pane fade" id="patent">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="tile">
                                    <div class="row" style="justify-content: center;">
                                        <div class="col-lg-6">
                                            <form>
                                                <div class="form-group">
                                                    <label class="xrequired">专利名称：</label>
                                                    <input class="form-control" id="patentItemName" type="text"
                                                           onblur="checkValue(this)"
                                                           placeholder="请输入专利名称">
                                                </div>
                                                <div class="form-group">
                                                    <label class="xrequired">专利类型：</label>
                                                    <select class="form-control" onchange="selValue(this)">
                                                        <option value="">请选择</option>
                                                        <option value="p1">实用新型专利</option>
                                                        <option value="p2">发明专利</option>
                                                    </select>
                                                    <input type="hidden" id="patentPatentType" value=""/>
                                                </div>
                                                <div class="form-group">
                                                    <label class="xrequired">专利号：</label>
                                                    <input class="form-control" id="patentPatentCode" type="text"
                                                           onblur="checkValue(this)"
                                                           placeholder="请输入专利号">
                                                </div>
                                                <div class="form-group">
                                                    <label class="">专利申请时间：</label>
                                                    <input class="form-control form_datetime" id="patentItemStartDate"
                                                           type="text"
                                                           placeholder="请选择专利申请时间" autocomplete="off">
                                                </div>
                                                <div class="form-group">
                                                    <label>专利授权时间：</label>
                                                    <input class="form-control form_datetime"
                                                           id="patentItemPublishDate"
                                                           type="text"
                                                           placeholder="请输入专利授权时间" autocomplete="off">
                                                </div>
                                                <div class="form-group">
                                                    <label class="xrequired">第一发明人：</label>
                                                    <select class="form-control select2_main" id="patentMainStaff"
                                                            data-placeholder="--请选择--">
                                                        <optgroup label="员工">
                                                            <option></option>
                                                            <c:forEach items="${staffList}" var="staff">
                                                                <option value="${staff.pkId}">${staff.staffName}</option>
                                                            </c:forEach>
                                                        </optgroup>
                                                    </select>
                                                </div>
                                                <div class="form-group">
                                                    <label class="">其他发明人：</label>
                                                    <select class="form-control select2_other" id="patentOtherStaff"
                                                            data-placeholder="--请选择--" multiple="">
                                                        <optgroup label="员工">
                                                            <c:forEach items="${staffList}" var="staff">
                                                                <option value="${staff.pkId}">${staff.staffName}</option>
                                                            </c:forEach>
                                                        </optgroup>
                                                    </select>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                    <div class="tile-footer">
                                        <button class="btn btn-primary" type="button" onclick="save('patent')">提交
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
    $(function () {
        updateValue();
    });

    $('a[data-toggle="tab"]').on('show.bs.tab', function (e) {
        var activeTab = $(e.target).attr("href").substr(1);
        select2Init(activeTab);
    });

    //赋更新值
    function updateValue() {
        $(".active.show").removeClass("active show");
        var projectName = "${project.techTypeEntity.name}";

        select2Init(projectName);
        if (projectName.valueOf() === "suggest") {
            $("#suggest").addClass("active show");
        }
        if (projectName.valueOf() === "ppt") {
            $("#ppt").addClass("active show");
        }
        if (projectName.valueOf() === "paper") {
            $("#paper").addClass("active show");
        }
        if (projectName.valueOf() === "QC") {
            $("#QC").addClass("active show");
        }
        if (projectName.valueOf() === "research") {
            $("#research").addClass("active show");
        }
        if (projectName.valueOf() === "patent") {
            $("#patent").addClass("active show");
        }

        var mainStaff = new Array();
        <c:forEach items="${project.mainStaffEntities}" var="project" varStatus="vst">
        mainStaff.push(${project.pkId});
        </c:forEach>
        var otherStaff = new Array();
        <c:forEach items="${project.otherStaffEntities}" var="project" varStatus="vst">
        otherStaff.push(${project.pkId});
        </c:forEach>
        $("#" + projectName + "ItemName").val("${project.itemName}");
        $("#" + projectName + "ItemContent").val("${project.itemContent}");
        $("#" + projectName + "ItemStartDate").val("${project.itemStartDate}".replace(/-/g,  "/"));
        $("#" + projectName + "ItemRewardClass").prev().val("${project.itemRewardClass}");
        $("#" + projectName + "ItemRewardClass").val("${project.itemRewardClass}");
        $("#" + projectName + "ItemRewardDate").val("${project.itemRewardDate}".replace(/-/g,  "/"));
        $("#" + projectName + "ItemPublishClass").prev().val("${project.itemPublishClass}");
        $("#" + projectName + "ItemPublishClass").val("${project.itemPublishClass}");
        $("#" + projectName + "ItemPublishDate").val("${project.itemPublishDate}".replace(/-/g,  "/"));
        $("#" + projectName + "MainStaff").val(mainStaff).trigger("change");
        $("#" + projectName + "OtherStaff").val(otherStaff).trigger("change");
        $("#" + projectName + "ItemReport").prev().val("${project.itemReport}");
        $("#" + projectName + "ItemReport").val("${project.itemReport}");
        $("#" + projectName + "PatentType").prev().val("${project.patentType}");
        $("#" + projectName + "PatentType").val("${project.patentType}");
        $("#" + projectName + "PatentCode").val("${project.patentCode}");
    }

    //初始化select2
    function select2Init(activeTab) {
        var mainstaff = $("#" + activeTab + "MainStaff");
        mainstaff.val(undefined);
        mainstaff.select2();
        var otherStaff = $("#" + activeTab + "OtherStaff");
        otherStaff.val(undefined);
        otherStaff.val('').trigger("change");
        otherStaff.select2({
            allowClear: true,
            maximumSelectionSize: 3
        });
        $(".select2-selection__rendered").addClass("form_select2");
        otherStaff.on("select2:select", function (evt) {
            var element = evt.params.data.element;
            var $element = $(element);
            $element.detach();
            $(this).append($element);
            $(this).trigger("change");
        });
    }

    $.fn.datepicker.dates['cn'] = {
        days: ["周日", "周一", "周二", "周三", "周四", "周五", "周六", "周日"],
        daysShort: ["日", "一", "二", "三", "四", "五", "六", "七"],
        daysMin: ["日", "一", "二", "三", "四", "五", "六", "七"],
        months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
        monthsShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
        today: "今天",
        clear: "清除"
    };

    $('.form_datetime').datepicker({
            autoclose: true,
            beforeShowDay: $.noop,
            calendarWeeks: false,
            clearBtn: false,
            daysOfWeekDisabled: [],
            endDate: Infinity,
            forceParse: true,
            format: 'yyyy/mm/dd',
            keyboardNavigation: true,
            language: 'cn',  //修改默认为cn
            minViewMode: 0,
            orientation: "auto",
            rtl: false,
            startDate: -Infinity,
            startView: 0,
            todayBtn: true,
            todayHighlight: true,
            weekStart: 0
        }
    );

    function checkValue(obj) {
        var object = $(obj);
        var elementValue = object.val();
        if (elementValue != null && elementValue != "") {
            object.addClass("is-valid").removeClass("is-invalid");
            object.parent().addClass("has-success").removeClass("has-danger");

        } else {
            object.addClass("is-invalid").removeClass("is-valid");
            object.parent().removeClass("has-success").addClass("has-danger");
        }
    }

    function selValue(object) {
        var obj = $(object);
        var selText = obj.find("option:selected").val();
        var selId = obj.next().attr("id");
        $("#" + selId).val(selText);
    }

    function isEmpty(obj) {
        if (typeof obj === 'undefined' || obj == null || obj === '' || obj.length === 0) {
            return true;
        } else {
            return false;
        }
    }

    function saveIsEmpty() {
        for (var i = 0; i < arguments.length; i++) {
            if (isEmpty(arguments[i])) {
                return true;
            }
        }
        return false;
    }

    function splitBy(mainStaffEntities, staffs) {
        for (var i = 0; i < staffs.length; i++) {
            mainStaffEntities.push({"pkId": staffs[i]});
        }
        return mainStaffEntities;
    }

    function StringToDate(str) {
        if (str) {
            var strDate = str.split(" ");
            var strDatepart = strDate[0].split("/");
            return new Date(strDatepart[0], strDatepart[1] - 1, strDatepart[2]);
        }
    }

    function save(type) {
        var pkId = $("#pkId").val();
        var itemName = $("#" + type + "ItemName").val();
        var itemContent = $("#" + type + "ItemContent").val();
        var itemStartDate = $("#" + type + "ItemStartDate").val();
        var itemRewardDate = $("#" + type + "ItemRewardDate").val();
        var itemRewardClass = $("#" + type + "ItemRewardClass").val();
        var itemPublishClass = $("#" + type + "ItemPublishClass").val();
        var itemPublishDate = $("#" + type + "ItemPublishDate").val();
        var itemReport = $("#" + type + "ItemReport").val();
        var patentCode = $("#" + type + "PatentCode").val();
        var mainStaff = $("#" + type + "MainStaff").val();
        var otherStaff = $("#" + type + "OtherStaff").val();
        var patentType = $("#" + type + "PatentType").val();
        var techType;
        var boo = true;
        alert("时间"+itemStartDate);
        alert("时间"+itemRewardDate);
        switch (type) {
            case "suggest":
                techType = 1;
                boo = saveIsEmpty(itemName, itemRewardClass, mainStaff);
                break;
            case "ppt":
                techType = 2;
                boo = saveIsEmpty(itemName, itemPublishClass, mainStaff);
                break;
            case "paper":
                techType = 3;
                boo = saveIsEmpty(itemName, itemPublishDate, mainStaff);
                break;
            case "QC":
                techType = 4;
                boo = saveIsEmpty(itemName, itemRewardClass, mainStaff);
                break;
            case "research":
                boo = saveIsEmpty(itemName, itemRewardClass, mainStaff);
                techType = 5;
                break;
            case "patent":
                techType = 6;
                boo = saveIsEmpty(itemName, patentCode, mainStaff, patentType);
                break;
            default:
                alert("填写信息有误！");
        }

        if (boo) {
            swal({
                title: "请填写必填信息！",
                text: '带' + '<label class="xrequired"></label>' + '为必填项，请按照要求填写井的信息！',
                html: true,
                type: "warning",
                showCancelButton: false,
                confirmButtonText: "确认",
                closeOnConfirm: false
            });
            return false;
        }

        var mainStaffEntities = [];
        mainStaffEntities = splitBy(mainStaffEntities, mainStaff);
        var otherStaffEntities = [];
        otherStaffEntities = splitBy(otherStaffEntities, otherStaff);
        alert("时间"+itemStartDate);
        alert("时间"+itemRewardDate);
        var techProject = {
            "pkId": pkId,
            "itemName": itemName,
            "itemContet": itemContent,
            "techTypeEntity": {
                "pkId": techType
            },
            "itemStartDate": StringToDate(itemStartDate),
            "itemRewardDate": StringToDate(itemRewardDate),
            "itemRewardClass": itemRewardClass,
            "itemPublishDate": StringToDate(itemPublishDate),
            "itemPublishClass": itemPublishClass,
            "itemReport": itemReport,
            "patentCode": patentCode,
            "mainStaffEntities": mainStaffEntities,
            "otherStaffEntities": otherStaffEntities,
            "patentType": patentType
        };
        var project = JSON.stringify(techProject);
        alert(project);
        $.ajax({
            url: '${ctx}/save_project_tech_innov',
            data: project,
            dataType: "text",
            type: 'POST',
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                $(".app-content").html(data)
            },
            error: function (data) {
                swal({
                    title: "信息添加失败！",
                    text: "错误代码：" + data.status + "\n" + "错误信息：" + data.responseText,
                    html: false,
                    type: "error",
                    showCancelButton: false,
                    confirmButtonText: "确认",
                    closeOnConfirm: false
                });
            }
        });
    }
</script>
